from django.db import models


class Project(models.Model):
    """
    项目模型
    """
    name = models.CharField(max_length=200, verbose_name='项目名称')
    description = models.TextField(blank=True, verbose_name='项目描述')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        verbose_name = '项目'
        verbose_name_plural = '项目'
        db_table = 'project_nav_project'
        ordering = ['id']
    
    def __str__(self):
        return self.name


class Group(models.Model):
    """
    组模型
    """
    name = models.CharField(max_length=200, verbose_name='组名称')
    project = models.ForeignKey(
        Project, 
        on_delete=models.CASCADE, 
        related_name='groups',
        verbose_name='所属项目'
    )
    description = models.TextField(blank=True, verbose_name='组描述')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        verbose_name = '组'
        verbose_name_plural = '组'
        db_table = 'project_nav_group'
        ordering = ['id']
    
    def __str__(self):
        return f'{self.project.name} - {self.name}'


class Satellite(models.Model):
    """
    卫星模型
    """
    name = models.CharField(max_length=200, verbose_name='卫星名称')
    group = models.ForeignKey(
        Group, 
        on_delete=models.CASCADE, 
        related_name='satellites',
        verbose_name='所属组'
    )
    description = models.TextField(blank=True, verbose_name='卫星描述')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        verbose_name = '卫星'
        verbose_name_plural = '卫星'
        db_table = 'project_nav_satellite'
        ordering = ['id']
    
    def __str__(self):
        return f'{self.group.project.name} - {self.group.name} - {self.name}'